package com.ttpai.boot.lbs.util;


import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class StringUtil {

    public static String findStrByRegex(String str, String regex) {
        String result = "";
        Pattern pattern = Pattern.compile(regex, Pattern.MULTILINE | Pattern.DOTALL);
        Matcher matcher = pattern.matcher(str);
        if (matcher.find()) {
            result = matcher.group();
        }
        return result;
    }

    public static String findStrByRegex(String str, String regex, int groupIndex) {
        String result = "";
        Pattern pattern = Pattern.compile(regex, Pattern.MULTILINE | Pattern.DOTALL);
        Matcher matcher = pattern.matcher(str);
        if (matcher.find()) {
            result = matcher.group(groupIndex);
        }
        return result;
    }

    public static List<String> listToStrings(String strList) {
        return Arrays.asList(strList.split(","));
    }

    public static List<String> listToStrings(String list, String split) {
        return Arrays.asList(list.split(split));
    }

    public static List<Long> listToLongs(String list, String split) {
        List<Long> longs = new ArrayList<Long>();
        String[] strings = list.split(split);
        for (String string : strings) {
            longs.add(Long.parseLong(string));
        }
        return longs;
    }

    public static void main(String[] args) {
        System.out.println(findStrByRegex("地铁8号线(市光路-沈杜公路)", "(地铁[0-9]{1,2}号线)"));
    }
}
